package com.ruoyi.jiajia.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.JiajiaUserMoneyChange;
import com.ruoyi.system.service.IJiajiaUserMoneyChangeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户金钱记录Controller
 * 
 * @author knd
 * @date 2021-10-29
 */
@Controller
@RequestMapping("/jiajia/moneyChange")
public class JiajiaUserMoneyChangeController extends BaseController
{
    private String prefix = "jiajia/moneyChange";

    @Autowired
    private IJiajiaUserMoneyChangeService jiajiaUserMoneyChangeService;

    @RequiresPermissions("jiajia:moneyChange:view")
    @GetMapping()
    public String moneyChange()
    {
        return prefix + "/moneyChange";
    }

    /**
     * 查询用户金钱记录列表
     */
    @RequiresPermissions("jiajia:moneyChange:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaUserMoneyChange jiajiaUserMoneyChange)
    {
        startPage();
        List<JiajiaUserMoneyChange> list = jiajiaUserMoneyChangeService.selectJiajiaUserMoneyChangeList(jiajiaUserMoneyChange);
        return getDataTable(list);
    }

    /**
     * 导出用户金钱记录列表
     */
    @RequiresPermissions("jiajia:moneyChange:export")
    @Log(title = "用户金钱记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaUserMoneyChange jiajiaUserMoneyChange)
    {
        List<JiajiaUserMoneyChange> list = jiajiaUserMoneyChangeService.selectJiajiaUserMoneyChangeList(jiajiaUserMoneyChange);
        ExcelUtil<JiajiaUserMoneyChange> util = new ExcelUtil<JiajiaUserMoneyChange>(JiajiaUserMoneyChange.class);
        return util.exportExcel(list, "用户金钱记录数据");
    }

    /**
     * 新增用户金钱记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户金钱记录
     */
    @RequiresPermissions("jiajia:moneyChange:add")
    @Log(title = "用户金钱记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaUserMoneyChange jiajiaUserMoneyChange)
    {
        return toAjax(jiajiaUserMoneyChangeService.insertJiajiaUserMoneyChange(jiajiaUserMoneyChange));
    }

    /**
     * 修改用户金钱记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaUserMoneyChange jiajiaUserMoneyChange = jiajiaUserMoneyChangeService.selectJiajiaUserMoneyChangeById(id);
        mmap.put("jiajiaUserMoneyChange", jiajiaUserMoneyChange);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户金钱记录
     */
    @RequiresPermissions("jiajia:moneyChange:edit")
    @Log(title = "用户金钱记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaUserMoneyChange jiajiaUserMoneyChange)
    {
        return toAjax(jiajiaUserMoneyChangeService.updateJiajiaUserMoneyChange(jiajiaUserMoneyChange));
    }

    /**
     * 删除用户金钱记录
     */
    @RequiresPermissions("jiajia:moneyChange:remove")
    @Log(title = "用户金钱记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaUserMoneyChangeService.deleteJiajiaUserMoneyChangeByIds(ids));
    }
}
